// 服务端渲染模板代码

const Vue = require('vue')
const server = require('express')()
const renderer = require('vue-server-renderer').createRenderer({
	template: require('fs').readFileSync('./index.template.html', 'utf-8')
})


// req 相当于request
// res 当当于response
server.get('*', (req, res) => {
  const app = new Vue({
    data: {
      url: req.url
    },
    template: `<div>now url: {{ url }}</div>`
  })
  
  const context = {
  	title: '冷灯看剑',
  	meta: `
  	<meta charset="utf-8">
		<meta xxx="2" >
  	`
  }
  
  renderer.renderToString(app, context, (err, html) => {
	  if (err) {
		  // res 相当于 response
		  res.status(500).end('Internal Server Error-' + err.message)
		  return
	  }
	  res.end(html)
  })
  

   
})

server.listen(8080)